package edu.kit.csl.cratyli.control;

import edu.kit.csl.cratyli.datatypes.Dictionary;

/**
 * Takes the sentence of the highest minimum weight.
 */
public class MinWeightSentenceTargetFunction extends SentenceTargetFunction {

	/* (non-Javadoc)
	 * @see edu.kit.csl.cratyli.control.SentenceTargetFunction#merge(edu.kit.csl.cratyli.datatypes.Dictionary, java.lang.String[], java.lang.String[])
	 */
	@Override
	public String merge(Dictionary dict, String[] prim, String[] sec) {
		double minSecWeight = Double.MAX_VALUE;
		for (String word : sec) {
			minSecWeight = Math.min(minSecWeight, dict.get(word).getWeight());
		}
		for (String word : prim) {
			if (minSecWeight > dict.get(word).getWeight()) {
				return arr2str(sec);
			}
		}
		return arr2str(prim);
	}
}
